package com.traitswu.simple.demo.controller;


import com.google.common.collect.ImmutableMap;
import com.traitswu.simple.demo.model.Avatar;
import com.traitswu.simple.demo.model.Sex;
import com.traitswu.simple.demo.model.User;
import com.traitswu.simple.demo.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@RestController
public class UserController {


    @Resource
    private UserService userService;


    @GetMapping("/status.ci")
    public Object status() {

        Runtime runtime = Runtime.getRuntime();

        int availableProcessors = runtime.availableProcessors();
        long freeMemory = runtime.freeMemory();
        long totalMemory = runtime.totalMemory();


        User u = new User();
        u.setName("zhangsan");
        u.setBirthDate(new Date());
        u.setSex(Sex.Boy);

        Avatar avatar = new Avatar();
        avatar.setName("NB");
        avatar.setUrl("http://google.com");
        u.setAvatar(avatar);
        System.out.println(userService.save(u));
        System.out.println(u.getId());
        return ImmutableMap.of(
                "available", availableProcessors,
                "freeMemory", freeMemory,
                "totalMemory", totalMemory
        );


    }

}
